package com.hm.oper_monitor.ui.tab;

import java.awt.Component;
import java.awt.Font;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTabbedPane;

import com.hm.common.util.SpringUtil;
import com.hm.oper_monitor.bean.ResourcesManager;

@SuppressWarnings("serial")
public class TabPanel extends JTabbedPane {
	private static TabPanel tabPanel;
	private ResourcesManager rm;
	private List<Component> panels = new LinkedList<Component>();

	private TabPanel() {
		rm = SpringUtil.getBean(ResourcesManager.class);
		this.setFont(new Font("Default", Font.PLAIN, 18));
//		setLayout(new GridLayout(1, 1));
//		this.setBounds(0, 0, rm.getScreenViewProp().getScreenWidth(), rm.getScreenViewProp().getScreenHeight());
	}

	public static TabPanel getTab() {
		if (tabPanel == null) {
			synchronized (TabPanel.class) {
				if (tabPanel == null) {
					tabPanel = new TabPanel();
				}
			}
		}
		return tabPanel;
	}

	public void addPanel(String title, Icon icon, Component component, String tip, int mnemonic) {
		this.addTab(title, icon, component, tip);//加入一个页面 
		this.setMnemonicAt(panels.size(), mnemonic);//设置快捷键
		panels.add(component);
	}

	private ImageIcon createImageIcon(String path) {
		URL url = TabPanel.class.getResource(path);
		if (url == null) {
			System.out.println("the image " + path + " is not exist!");
			return null;
		}
		return new ImageIcon(url);
	}
}
